package com.winning.cqs.pregnantbabycare_cqs_v1.adapter;

import java.util.List;

import com.winning.cqs.pregnantbabycare_cqs_v1.R;
import com.winning.cqs.pregnantbabycare_cqs_v1.adapter.HealthDeviceListViewAdapter.ViewHolder;
import com.winning.cqs.pregnantbabycare_cqs_v1.domain.HealthDeviceDomain;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class HealthDeviceLinkListViewAdapter extends
		ArrayAdapter<HealthDeviceDomain> {

	private int resource;

	public HealthDeviceLinkListViewAdapter(Context context, int resource,
			List<HealthDeviceDomain> objects) {
		super(context, resource, objects);
		// TODO Auto-generated constructor stub
		this.resource = resource;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		View view = null;
		ViewHolder holder = null;
		HealthDeviceDomain device = getItem(position);
		if (convertView == null) {
			view = LayoutInflater.from(getContext()).inflate(resource, null);
			holder = new ViewHolder();
			holder.img = (ImageView) view
					.findViewById(R.id.item_health_device_link_img);
			holder.name = (TextView) view
					.findViewById(R.id.item_health_device_link_tv);
			view.setTag(holder);

		} else {
			view = convertView;
			holder = (ViewHolder) view.getTag();
		}
		holder.img.setImageResource(device.getDevice_imgID());
		holder.name.setText(device.getDevice_name());
		return view;
	}

	static class ViewHolder {
		ImageView img;
		TextView name;
	}

}
